<template>
    <div className="current-time">
        {{ currentTime }}
    </div>
</template>

<script setup>
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import {ref} from "vue"

dayjs.extend(relativeTime)

const currentTime = ref('')

// 初始化显示当前时间
const updateTime = () => {
    currentTime.value = dayjs().format('YYYY-MM-DD HH:mm:ss')
    // 或者使用相对时间：currentTime.value = dayjs().fromNow();
}
setInterval(updateTime, 1000)

</script>

<style scoped>
.current-time {
    font-size: 24px;
}
</style>